//
//  UntitledViewController.m
//  Untitled
//

#import "UntitledViewController.h"

@implementation UntitledViewController

@synthesize counter;
@synthesize username, language;
@synthesize age;

- (void)myMethod
{
	NSString *myString = @"some value";
	for (int i=0; i<9999; ++i) {
		NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
		
		NSString *myString2 = [myString stringByAppendingString:
							   [NSString stringWithFormat:@"%d", myString, i]];
		
		[pool release];
	}
}

- (void)myStringExample
{
	NSString *fileName = @"somefile.txt";
	NSString *fileExtension = [fileName pathExtension];
	
	NSString *myString = @" one two three ";
	NSString *trimmed = [myString stringByTrimmingCharactersInSet:
						 [NSCharacterSet whitespaceCharacterSet]];
	
	NSString *string1 = @"some string";
	NSString *string2 = @"some other string";
	NSString *string3 = @"SoMe StRiNg";
	NSString *string4 = @"some other string";
	
	NSLog(@"%i", [string2 isEqualToString:string4]);
	NSLog(@"%i", [string1 isEqualToString:string3]);
	NSLog(@"%i", ([string1 caseInsensitiveCompare:string3] == NSOrderedSame));
	
	NSString *n = @"12345";
	double d = [n doubleValue];
	int i = [n intValue];
	NSLog(@"%f, %d", d, i);
	
	NSURL *url = [NSURL URLWithString:@"http://google.com"];
	NSString *pageContents = [NSString stringWithContentsOfURL:url];
	
	NSString *numberString = @"one two three";
	NSRange foundRange = [numberString rangeOfString:@"two"];
	NSString *oneString = [numberString substringToIndex:3];
	NSString *twoString = [numberString substringWithRange:NSMakeRange(4, 3)];
	NSString *threeString = [numberString substringFromIndex:8];
	
	NSString *repeatString = [numberString
							  stringByReplacingOccurrencesOfString:@"three"
							  withString:@"four"];
	BOOL found = ([numberString rangeOfString:@"two1"].location != NSNotFound);
	
	NSString *stringa = @"one";
	NSString *stringb = [stringa stringByAppendingString:@" two"];
	
	NSLog(@"%i - %i", foundRange.location, foundRange.length);
	NSLog(@"%@", repeatString);
	NSLog(@"[%@] [%@] [%@]", oneString, twoString, threeString);
	NSLog(@"%@", [numberString componentsSeparatedByString:@" "]);
}


/*
- (void)viewDidLoad {
    [super viewDidLoad];
	tableView = [[UITableView alloc] init];
	
	NSString *myString = [NSString stringWithString:@"foobar"];
	NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObject:nil];
	NSMutableArray *arr = [NSMutableArray arrayWithObject:nil];
	
	UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	UIImage *img = [UIImage imageNamed:@"apple.png"];
	UIFont *font = [UIFont systemFontOfSize:14.0];
}
 */

/*
- (void)dealloc {
	[tableView release];
    [super dealloc];
}
 */

#define MY_NOTIFICATION @"MY_NOTIFICATION"

- (void)doSomething:(NSNotification *)aNote {
	NSDictionary *myDict = [aNote object];
	NSLog(@"%@", myDict);
}

/*
- (void)viewDidLoad {
	
	[super viewDidLoad];
	
	NSString *myString = @"some value";
	NSDictionary *myDict = [[NSDictionary alloc] initWithObjectsAndKeys:myString, @"firstObject", nil];
	
	[[NSNotificationCenter defaultCenter] addObserver:self
											 selector:@selector(doSomething:)
												 name:MY_NOTIFICATION
											   object:nil];
	
	[[NSNotificationCenter defaultCenter] postNotificationName:MY_NOTIFICATION
														object:myDict];
	
}
*/

- (void)dealloc {
	
	[[NSNotificationCenter defaultCenter] removeObserver:self];
	[super dealloc];
}

- (void)myTimerAction:(NSTimer *)timer {
	NSLog(@"timer fired!: %@", [timer userInfo]);
}

/*
- (void)viewDidLoad {
	
	NSTimeInterval secondsPerDay = 24*60*60;
	NSDate *tomorrow = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay];
	myTimer = [[NSTimer alloc] initWithFireDate:tomorrow
									   interval:10.0
										 target:self
									   selector:@selector(myTimerAction:)
									   userInfo:nil repeats:NO];
	[[NSRunLoop mainRunLoop] addTimer:myTimer forMode:NSDefaultRunLoopMode];
	
	myTimer2 = [NSTimer timerWithTimeInterval:1.0
									   target:self
									 selector:@selector(myTimerAction:)
									 userInfo:nil repeats:NO];
}
 */

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
	return NO;
}

/*
- (void)viewDidLoad {
	
	CGRect rect = CGRectMake(10,10,100,44);
	
	UITextField *myTextField = [[UITextField alloc] initWithFrame:rect];
	myTextField.delegate = self;
	
	[self.view addSubview:myTextField];
	[myTextField release];
}
 */

- (void)buttonTap:(id)sender {
	NSLog(@"Button tapped");
}

- (void)viewDidLoad {
	
	CGRect rect = CGRectMake(10, 10, 100, 44);
	UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	[myButton setFrame:rect];
	[myButton addTarget:self
				 action:@selector(buttonTap:)
	   forControlEvents:UIControlEventTouchUpInside];
	
	[self.view addSubview:myButton];
}

@end
